<template>
  <div class="edit-container">
    <el-form v-loading="saveLoading" ref="form" :model="form" :rules="rules" label-width="120px" @submit.native.prevent>
      <el-row>
        <el-col :span="12">
          <el-form-item label="类型：" prop="houseType">
            <el-select v-model="form.houseType" placeholder="类型" >
              <el-option
                  v-for="item in houseTypeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.label">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="租赁证编号：" prop="leaseCertificateNumber">
            <el-input v-model="form.leaseCertificateNumber" placeholder="租赁证编号" style="width: 300px">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="片区：" prop="areaName">
            <el-input v-model="form.areaName" placeholder="片区" style="width: 300px"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="街（巷、路）" prop="streetName">
            <el-input v-model="form.streetName" placeholder="街（巷、路）"  style="width: 300px"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="号（楼、院）：" prop="courtyardNumber">
            <el-input v-model="form.courtyardNumber" placeholder="号（楼、院）" style="width: 300px"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单元：" prop="unitNumber">
              <el-input-number
                  v-model.number="form.unitNumber"
                  :min="1"
                  :max="8"
                  :step="1"
              ></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="楼号：" prop="buildingNumber">
              <el-input-number
                  v-model.number="form.buildingNumber"
                  :min="1"
                  :max="100"
                  :step="1"
              ></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="房号：" prop="roomNumber">
              <el-input-number
                  v-model.number="form.roomNumber"
                  :min="1"
                  :max="10"
                  :step="1"
              ></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <el-button v-loading="saveLoading" element-loading-background="rgba(0, 0, 0, 0.3)" type="primary"
                   @click="handlerSubmit" v-has-permi="['admin:house:information:save']">保存
        </el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {amountSave} from "@/api/payment";

export default {
  components: {},
  props: {
    isCreate: {
      type: Number,
      required: true
    },
    editData: {
      type: Object,
      default: () => {
        return {rules: []}
      }
    },
  },
  data() {
    return {
      form: {
        id: null,
        houseType:'',
        leaseCertificateNumber:'',
        areaName:'',
        streetName:'',
        courtyardNumber: '',
        unitNumber: 0,
        buildingNumber: 0,
        roomNumber: 0,
        buildingArea:'',
        usableArea:'',
        houseStatus:'',
      },
      rules: {
        quota: [{required: true, message: '请上填写金额', trigger: ['blur']}],
      },
      saveLoading: false,
      formLoading: false,
      houseTypeOptions: [{
        value: '1',
        label: '直管公房'
      }, {
        value: '2',
        label: '廉租房'
      }, {
        value: '3',
        label: '公租房'
      }, {
        value: '4',
        label: '经济适用房'
      }, {
        value: '5',
        label: '过渡房'
      }, {
        value: '6',
        label: '代管产'
      }, {
        value: '7',
        label: '廉租住房'
      }],
    }
  },
  mounted() {
    if (this.isCreate === 1) {
      this.getDetail();
    }
  },
  methods: {
    getDetail() {
      this.form = this.editData
    },
    handlerSubmit() {
      if (this.saveLoading) {
        return
      }
      this.$refs.form.validate(valid => {
        if (!valid) return;
        this.saveLoading = true;
        amountSave(this.form).then(() => {
          this.$message.success('保存成功');
          this.close();
        }).finally(() => {
          this.saveLoading = false
        })
      })
    },
    close() {
      this.$emit('hideEditDialog');
    },
  }
}
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
